#ifndef JOYSTICK_H_INCLUDED
#define JOYSTICK_H_INCLUDED

#include "types.h"

class Joystick : public Instance
{
    public:
        Joystick(const string& name = "Untitled", ClassId* classId = sClassId, int deviceIndex = -1);
        virtual ~Joystick();

        static Joystick* getActive(unsigned int index = 0);
        static bool detectActive();

        // Event handling
        static void handleAxisEvent(SDL_JoyAxisEvent* event, float dt);
        virtual void onAxisMotion(Uint8 axis, int x, float dt);
        static void handleBallEvent(SDL_JoyBallEvent* event, float dt);
        virtual void onBallMotion(Uint8 ball, int dx, int dy, float dt);
        static void handleHatEvent(SDL_JoyHatEvent* event, float dt);
        virtual void onHatMotion(Uint8 hat, Uint8 value, float dt);
        static void handleButtonEvent(SDL_JoyButtonEvent* event, float dt);
        virtual void onButtonDown(Uint8 button, float dt);
        virtual void onButtonUp(Uint8 button, float dt);

        // Instance
        DECLARE_CLASSID(Joystick);
        virtual bool load(DataStream* ds = 0);
        virtual bool save(DataStream* ds = 0);

    private:
        static vector<Joystick*> sActives;

        SDL_Joystick* mSdlJoystick;
};

#endif // JOYSTICK_H_INCLUDED
